<!DOCTYPE html>
<html lang="zh-CN">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>

</body>
<script>
  let obj = {
    name: "cz",
    age: 18,
    msg: {
      say: "打起来了..."
    },
    color: ["pind", "好人"]
  };

  // 使用函数递归的方法
  let objs = {};
  let deepCopy = (newObj, oldObj) => {
    for (let key in oldObj) {
      let item = oldObj[key]; //获取属性值
      if (item instanceof Array) { //判断是否属于数组
        newObj[key] = [];
        deepCopy(newObj[key], item);
      } else if (item instanceof Object) {
        // newObj[key] 属性名
        newObj[key] = {};
        deepCopy(newObj[key], item);
      } else {
        newObj[key] = oldObj[key];
      };
    };
  };
  deepCopy(objs, obj);
  console.log(objs);
</script>

</html>